package com.zsc.wxm.ysh.anjo.member.controller;


import com.zsc.wxm.ysh.anjo.member.service.RoleService;
import com.zsc.wxm.ysh.anjo.result.Result;
import com.zsc.wxm.ysh.anjo.service.base.model.member.dto.MemberRoleDTO;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author playmaker
 * @since 2021-01-04
 */
@RestController
@RequestMapping("/user/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @PostMapping("/add-role")
    @ApiOperation(value = "增加角色", httpMethod = "POST")
    public Result addRole(@RequestParam @ApiParam("角色名") String name) {
        roleService.addRole(name);
        return Result.ok("增加成功");
    }

    @GetMapping("/get-user-roles/{memberId}")
    @ApiOperation(value = "获取用户角色", httpMethod = "GET")
    public Result getUserRoles(@PathVariable Long memberId) {
        return Result.ok("获取成功", roleService.findRoleByUserId(memberId));
    }

    @PostMapping("/give-member-to-roles")
    @ApiOperation(value = "给用户分配角色", httpMethod = "POST")
    public Result giveMemberToRoles(MemberRoleDTO params) {
        roleService.giveMemberToRoles(params.getMemberId(), params.getRoleIds());
        return Result.ok("分配成功");
    }

}

